<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-12-01 15:48
 *
 * Version: 2.0
 */

namespace App\Modules\Gift\Controllers;


use App\Lib\Facades\FLAuth;
use App\Modules\Gift\Services\GiftService;
use App\Modules\Gift\Validators\GiftControllerValidator;
use Flower\Core\Http\BaseController;
use Flower\Facades\Flower;
use Illuminate\Http\Request;

class GiftController extends BaseController
{
	protected $giftService;

	public function __construct(GiftService $giftService)
	{
		$this->giftService = $giftService;
	}

	public function getRules()
	{
		return GiftControllerValidator::getRules(); // TODO: Change the autogenerated stub
	}


	public function lst(){
		$result = $this->giftService->lst();
		return $this->handleApiResult($result);
	}

	/**
	 * 检测是否能发礼物
	 * @param Request $request
	 * @return mixed
	 * @throws \App\Exceptions\NotFoundException
	 */
	public function checkMemberCanSendGift(Request $request){
		$giftId = $request->input('gift_id');
		$result = $this->giftService->checkMemberCanSendGift($giftId,FLAuth::id());
		return $this->handleApiResult($result);
	}


	/**
	 * 用户发礼物给理发师
	 * @param Request $request
	 * @return mixed
	 * @throws \App\Exceptions\AllValidatorException
	 * @throws \App\Exceptions\DbException
	 * @throws \App\Exceptions\NotFoundException
	 */
	public function memberSendGift(Request $request){
		$giftId = $request->input('gift_id');
		$user_id = $request->input('user_id');
		$live_id = $request->input('live_id');
		$result = $this->giftService->sendGiftToBarber($giftId,FLAuth::id(),$user_id,$live_id);
		return $this->handleApiResult($result);
	}


	/**
	 * 礼物列表
	 * @param Request $request
	 * @return mixed
	 * @throws \App\Exceptions\AllValidatorException
	 */
	public function giftListByBarberId(Request $request){
		$live_id = $request->input('live_id');
		$result = $this->giftService->getListByBarberId(FLAuth::id(),$live_id);
		return $this->handleApiResult($result);
	}
}